
import * as PIXI from 'pixi.js';
import Text from 'components/text';
// import Image from 'components/image';
import Image from 'components/image';
import injectStore from 'components/injectStore';
const { Container } = PIXI;

@injectStore
export default class ItemModal {
  constructor({parent, onGetItem, store, ...props}) {

    const {height, box, top, width} = props;
    this.onGetItem = onGetItem;
    this.parent = parent;
    this.container = new Container();

    const getItems = store.items.filter(item => JSON.stringify(box.getItems).indexOf(item.key) > -1);

    getItems.forEach((item, index) => {
      let img = new Image({src: item.src, top: 50 + index * 420});
      const scale = 150 / img.height;
      img.height = 150;
      img.width = img.width * scale;
      img.x = (width - img.width) / 2;

      let getText = new Text({value: item.getText, top: 230 + index * 420, fontSize: 34, fontWeight: 600});
      getText.x = (width - getText.width) / 2;

      let useText = new Text({value: item.useText, top: 275 + index * 420, fontSize: 28});
      useText.x = (width - useText.width) / 2;

      this.container.addChild(img);
      this.container.addChild(getText);
      this.container.addChild(useText);

    });


    this.container.y = top;
    this.container.x = (window.CFG.view.width - width) / 2;


  }
}
